// pages/myOrder/myOrder.js
import { request } from '../../utils/util';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    videos:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    const  {data}  = await request('GET','/order/getOrdersByState',{state:1});//支付成功订单
    let videos = [];
    data.forEach(item => {
        if (item.product.product_type == 0) {//视频
            videos.push(item.product);
        }
    })
    this.setData({
        videos
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  changTab: async function (e) {
    const detail = Number(e.currentTarget.dataset.value)
    const { data } = await request('GET','/order/getOrdersByState',{state:detail});
    this.setData({
        detail: detail,
        orders: data
    })
  },
  toMyVideoDetail: function(e) {
    const id = Number(e.currentTarget.dataset.value)
    wx.navigateTo({
      url: '/pages/myVideoDetail/myVideoDetail?id='+id,
    })
  }
})